package com.advanced.commonlyUsedClass_2.packaging;

import java.util.Scanner;

/**
 * 编写一个字符浏览器，输入字符串以及需要查找的字符或字符串，
 * 浏览器自动定位
 所有出现该字符或字符串的位置。
 *
 * @author: Jovi
 * @createTime: 2017-06-06 11:54
 **/
public class SearchString {

    public static void main(String[] args) {
        System.out.println("Please enter a string：");
        Scanner sc = new Scanner(System.in);
        String strs = sc.next();
        System.out.println("Please enter a char what to find:");
        String str =sc.next();
        int fromIndex = 0 ;
        System.out.println("\""+str+"\"the position is：");
        while (true) {
            int index = strs.indexOf(str, fromIndex);
            if (index == -1) {
                break;
            }
            System.out.print(index + "，");
            fromIndex = index + 1;
        }
    }
}
